package com.tgy.leetcode;

import java.util.Arrays;

/**
 * @Author: tgy
 * @Date: 12/25/20 1:39 PM
 *
 * https://leetcode-cn.com/problems/assign-cookies/
 */
public class _455_分发饼干 {

    public int findContentChildren(int[] g, int[] s) {

        if (g == null || s == null || g.length == 0 || s.length == 0) {

            return 0;
        }

        Arrays.sort(g);
        Arrays.sort(s);

        /**
         *[10,9,8,7]
         * [7,8,9,10]
         * [5,6,7,8]
         *
         */

        int childs = 0;
        for (int i = 0; i < s.length; i++) {

            int es = s[i];

            if (childs == g.length) {

                break;
            }

            if (es >= g[childs]) {

                childs++;
            }
        }

        return childs;
    }
}
